﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace week9_textBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void _textBox1_MouseUp(object sender, MouseEventArgs e)
        {

        }

        private void SetRowCOlInfo()
        {
            //int row = 4;
            //int col = 17;

            int index = _textBox1.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引
            int line = _textBox1.GetLineFromCharIndex(index) + 1;//得到当前的行号，从0开始，索引+1.
            int col = _textBox1.SelectionStart - index + 1;//.SelectionStart得到光标所在位置的索引 减去 当前行第一个字符的位置=光标所在的列数（从0开始）


            mi_Row.Text = line.ToString() + "行";
            mi_Col.Text = col.ToString() + "列";
        }


        private void _textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            SetRowCOlInfo();
        }

        private void _textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void MI_open_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                System.IO.StreamReader sr;
                sr = new System.IO.StreamReader(openFileDialog1.FileName,Encoding.UTF8);
                _textBox1.Text = sr.ReadToEnd();
                sr.Close();
                
            }

        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }
    }
}
